package com.sunwayhorizo.health.hl7.persistent;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.sunwayhorizo.health.hl7.factories.ReferenceModifier;
import com.sunwayhorizo.health.hl7.persistent.pk.RimCoreRolesPK;

@Entity
@AttributeOverrides({
/*
 * @AttributeOverride(name = "systemId", column = @Column(name = "ROLE_ID")),
 * 
 * @AttributeOverride(name = "versionNum", column = @Column(name =
 * "ROLE_VERSION_NUM")),
 */
@AttributeOverride(name = "codeEtsId", column = @Column(name = "ROLE_CODE_ETS_ID")) })
@TableGenerator(name = "Role_IdGenerator", table = "RIM_Id_Generator", pkColumnName = "pkColumn", valueColumnName = "valueColumn", pkColumnValue = "Role_Id")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "PARTITION_BY_CLASS", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("RimCoreRoles")
@Table(name = "RIM_CORE_ROLES")
@IdClass(RimCoreRolesPK.class)
public class RimCoreRoles extends InfrastructureRoot
{

    // ϵͳ���Ĺ���
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "Role_IdGenerator")
    @Column(name = "ROLE_ID", nullable = false)
    private Long roleId;
    @Id
    @Column(name = "ROLE_VERSION_NUM", nullable = false)
    private Long roleVersionNum;

    // Role参与Act
    @OneToMany(mappedBy = "roleParticipation", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<? extends RimCoreActPrtcptns> rolePrtcptnsList = new ArrayList<RimCoreActPrtcptns>();

    // Role维护Ii、addr 、teladdr
    @OneToMany(mappedBy = "rimCoreRoles", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreRoleIi> roleIiList = new ArrayList<RimCoreRoleIi>();

    @OneToMany(mappedBy = "rimCoreRoles", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreRoleCdSets> roleCdSetsList = new ArrayList<RimCoreRoleCdSets>();

    @OneToMany(mappedBy = "rimCoreRoles", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreRoleAddrs> roleAddrsList = new ArrayList<RimCoreRoleAddrs>();

    @OneToMany(mappedBy = "rimCoreRoles", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<RimCoreRoleTelAddrs> roleTelAddrsList = new ArrayList<RimCoreRoleTelAddrs>();

    /**
     * 创建sourceRoleRimCoreRoleLink集合，映射RimCoreRoleLink
     * 
     * @author jinzw
     * @date 2010-11-16
     */
    @OneToMany(mappedBy = "sourceRole", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<? extends RimCoreRoleLink> sourceRoleRimCoreRoleLink = new ArrayList<RimCoreRoleLink>();

    /**
     * 创建targetRoleRimCoreRoleLink集合，映射RimCoreRoleLink
     * 
     * @author jinzw
     * @date 2010-11-16
     */
    @OneToMany(mappedBy = "targetRole", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<? extends RimCoreRoleLink> targetRoleRimCoreRoleLink = new ArrayList<RimCoreRoleLink>();

    // Roles 被Entity 维护
    @ManyToOne
    @JoinColumns({ @JoinColumn(name = "PLAYER_ID", referencedColumnName = "ENTITY_ID"),
            @JoinColumn(name = "PLAYER_VERSION_NUM", referencedColumnName = "ENTITY_VERSION_NUM") })
    private RimCoreEntities playerEntities;

    @JoinColumns({ @JoinColumn(name = "SCOPER_ID", referencedColumnName = "ENTITY_ID"),
            @JoinColumn(name = "SCOPER_VERSION_NUM", referencedColumnName = "ENTITY_VERSION_NUM") })
    private RimCoreEntities scoperEntities;

    @OneToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "CERTIFICATE_TXT_ED_ID", referencedColumnName = "ED_ID")
    private RimCoreEds rimCoreEdsCertificateTxtEdId =new RimCoreEds();

    @OneToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "EM_HAZARD_EXPOSURE_ED_ID", referencedColumnName = "ED_ID")
    private RimCoreEds rimCoreEdsEmHazardExposureEdId=new RimCoreEds() ;

    @OneToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "EM_PROTECTIVE_EQP_ED_ID", referencedColumnName = "ED_ID")
    private RimCoreEds rimCoreEdsEmProtectiveEqpEdId = new RimCoreEds() ;


    public RimCoreRoles()
    {
        Long i = new Long(1);
        roleVersionNum = i;
    }


    public RimCoreRoles(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
        Long i = new Long(1);
        roleVersionNum = i;
    }


    /*
     * //在participation 中加入role public RimCoreActPrtcptns
     * addRolePrtcptns(RimCoreActPrtcptns actPrtcptns) {
     * getRolePrtcptnsList().add(actPrtcptns);
     * actPrtcptns.setRoleparticipation(this); return actPrtcptns; }
     * 
     * public RimCoreActPrtcptns removeRolePrtcptns(RimCoreActPrtcptns
     * actPrtcptns) { getRolePrtcptnsList().remove(actPrtcptns);
     * actPrtcptns.setRoleparticipation(null); return actPrtcptns; }
     */

    private void setRolePrtcptnsList(List<RimCoreActPrtcptns> rolePrtcptnsList)
    {
        this.rolePrtcptnsList = rolePrtcptnsList;
    }


    public List<? extends RimCoreActPrtcptns> getRolePrtcptnsList()
    {
        return rolePrtcptnsList;
    }


    protected void setPlayerEntities(RimCoreEntities playerEntities)
    {
        this.playerEntities = playerEntities;
    }


    public RimCoreEntities getPlayerEntities()
    {
        return playerEntities;
    }


    protected void setScoperEntities(RimCoreEntities scoperEntities)
    {
        this.scoperEntities = scoperEntities;
    }


    public RimCoreEntities getScoperEntities()
    {
        return scoperEntities;
    }


    // RoleIi
    protected void setRoleIiList(List<RimCoreRoleIi> roleIiList)
    {
        this.roleIiList = roleIiList;
    }


    public List<RimCoreRoleIi> getRoleIiList()
    {
        return roleIiList;
    }


    protected RimCoreRoleIi addRoleIi(RimCoreRoleIi roleIi)
    {
        getRoleIiList().add(roleIi);
        roleIi.setRimCoreRoles(this);
        return roleIi;
    }


    protected RimCoreRoleIi removeRoleIi(RimCoreRoleIi roleIi)
    {
        getRoleIiList().remove(roleIi);
        roleIi.setRimCoreRoles(null);
        return roleIi;
    }


    // RoleCdSets
    protected void setRoleCdSetsList(List<RimCoreRoleCdSets> roleCdSetsList)
    {
        this.roleCdSetsList = roleCdSetsList;
    }


    public List<RimCoreRoleCdSets> getRoleCdSetsList()
    {
        return roleCdSetsList;
    }


    protected RimCoreRoleCdSets addRoleCdSets(RimCoreRoleCdSets roleCdSets)
    {
        getRoleCdSetsList().add(roleCdSets);
        roleCdSets.setRimCoreRoles(this);
        return roleCdSets;
    }


    protected RimCoreRoleCdSets removeRoleCdSets(RimCoreRoleCdSets roleCdSets)
    {
        getRoleCdSetsList().add(roleCdSets);
        roleCdSets.setRimCoreRoles(null);
        return roleCdSets;
    }


    // RoleAddrs
    protected void setRoleAddrsList(List<RimCoreRoleAddrs> roleAddrsList)
    {
        this.roleAddrsList = roleAddrsList;
    }


    public List<RimCoreRoleAddrs> getRoleAddrsList()
    {
        return roleAddrsList;
    }


    protected RimCoreRoleAddrs addRoleAddrs(RimCoreRoleAddrs roleAddrs)
    {
        getRoleAddrsList().add(roleAddrs);
        roleAddrs.setRimCoreRoles(this);
        return roleAddrs;
    }


    protected RimCoreRoleAddrs removeRoleAddrs(RimCoreRoleAddrs roleAddrs)
    {
        getRoleAddrsList().remove(roleAddrs);
        roleAddrs.setRimCoreRoles(null);
        return roleAddrs;
    }


    // RoleTelAddrs
    protected void setRoleTelAddrsList(List<RimCoreRoleTelAddrs> roleTelAddrsList)
    {
        this.roleTelAddrsList = roleTelAddrsList;
    }


    public List<RimCoreRoleTelAddrs> getRoleTelAddrsList()
    {
        return roleTelAddrsList;
    }


    protected RimCoreRoleTelAddrs addRoleTelAddrs(RimCoreRoleTelAddrs roleTelAddrs)
    {
        getRoleTelAddrsList().add(roleTelAddrs);
        roleTelAddrs.setRimCoreRoles(this);
        return roleTelAddrs;
    }


    protected RimCoreRoleTelAddrs removeRoleTelAddrs(RimCoreRoleTelAddrs roleTelAddrs)
    {
        getRoleTelAddrsList().remove(roleTelAddrs);
        roleTelAddrs.setRimCoreRoles(null);
        return roleTelAddrs;
    }


    // RimCoreRoleLink
    public List<? extends RimCoreRoleLink> getSourceRoleRimCoreRoleLink()
    {
        return sourceRoleRimCoreRoleLink;
    }


    private void setSourceRoleRimCoreRoleLink(List<RimCoreRoleLink> sourceRoleRimCoreRoleLink)
    {
        this.sourceRoleRimCoreRoleLink = sourceRoleRimCoreRoleLink;
    }


    protected RimCoreRoleLink removeSourceRole(RimCoreRoleLink rimCoreRoleLink)
    {
        getSourceRoleRimCoreRoleLink().remove(rimCoreRoleLink);
        rimCoreRoleLink.setSourceRole(null);
        return rimCoreRoleLink;
    }


    public List<? extends RimCoreRoleLink> getTargetRoleRimCoreRoleLink()
    {
        return targetRoleRimCoreRoleLink;
    }


    private void setTargetRoleRimCoreRoleLink(List<RimCoreRoleLink> targetRoleRimCoreRoleLink)
    {
        this.targetRoleRimCoreRoleLink = targetRoleRimCoreRoleLink;
    }


    protected RimCoreRoleLink removeTargetRole(RimCoreRoleLink rimCoreRoleLink)
    {
        getTargetRoleRimCoreRoleLink().remove(rimCoreRoleLink);
        rimCoreRoleLink.setTargetRole(null);
        return rimCoreRoleLink;
    }


    protected void setRimCoreEdsCertificateTxtEdId(RimCoreEds rimCoreEdsCertificateTxtEdId)
    {
        this.rimCoreEdsCertificateTxtEdId = rimCoreEdsCertificateTxtEdId;
    }


    protected RimCoreEds getRimCoreEdsCertificateTxtEdId()
    {
        return rimCoreEdsCertificateTxtEdId;
    }


    protected void setRimCoreEdsEmHazardExposureEdId(RimCoreEds rimCoreEdsEmHazardExposureEdId)
    {
        this.rimCoreEdsEmHazardExposureEdId = rimCoreEdsEmHazardExposureEdId;
    }


    protected RimCoreEds getRimCoreEdsEmHazardExposureEdId()
    {
        return rimCoreEdsEmHazardExposureEdId;
    }


    protected void setRimCoreEdsEmProtectiveEqpEdId(RimCoreEds rimCoreEdsEmProtectiveEqpEdId)
    {
        this.rimCoreEdsEmProtectiveEqpEdId = rimCoreEdsEmProtectiveEqpEdId;
    }


    protected RimCoreEds getRimCoreEdsEmProtectiveEqpEdId()
    {
        return rimCoreEdsEmProtectiveEqpEdId;
    }


    public void setRoleId(Long roleId)
    {
        this.roleId = roleId;
    }


    public Long getRoleId()
    {
        return roleId;
    }


    public void setRoleVersionNum(Long roleVersionNum)
    {
        this.roleVersionNum = roleVersionNum;
    }


    public Long getRoleVersionNum()
    {
        return roleVersionNum;
    }
}
